package com.kgcx.organization.rabbitmq.consumer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.kgcx.common.client.order.pojo.Order;
import com.kgcx.common.rabbitmq.consts.QueueConst;
import com.kgcx.organization.domain.AbstractParking;
import com.kgcx.organization.service.DriverService;

/**
 * 订单行程开始时状态变更
 */
@Component
public class DriverOrderStartConsumer {
    private static final Logger LOG = LoggerFactory.getLogger(DriverOrderStartConsumer.class);

    @Autowired
    private DriverService driverService;

    @RabbitListener(queues = QueueConst.DRIVER_ORDER_START, errorHandler = "custRabbitListenerErrorHandler")
    public void precess(String json) {
        LOG.info("收到行程开始的MQ消息。\n" + json);

        Order order = JSONObject.parseObject(json, Order.class);
        if (null != order.getDriverId()) {
            driverService.updateParkState(order.getDriverId(), AbstractParking.STATUS_LEFT);
        }
    }

}
